﻿Imports System.Text.RegularExpressions

Public Class Util
    Public Shared Function IsOnlyNumber(ByVal strText As String) As Boolean
        Dim validator As New Regex("^\d*[0-9]$")
        If validator.IsMatch(strText.ToLower()) Then
            Return True
        Else
            Return False
        End If
    End Function
    Public Shared Function IsPhone(ByVal phone As String) As Boolean
        Dim temp As String = ""
        Dim result As Boolean = True
        Dim phoneRegex As String = "\d{10}"
        temp = Util.FilterPhone(phone.Trim)
        If Left(phone.Trim, 1) <> "0" Then
            If Not Regex.IsMatch(temp, phoneRegex) Then
                result = False
            End If
            If (temp.Length <> 10) Then
                result = False
            End If
        End If
        IsPhone = result
    End Function
    Public Shared Function FilterPhone(ByVal phone As String) As String
        Dim result As String = ""
        Dim iCtr As Integer = 0
        Dim sValidString As String = "0123456789"

        phone = phone.Trim
        If Left(phone, 1).Equals("+") Then
            phone = String.Format("011{0}", Right(phone, phone.Length - 1))
        End If
        For iCtr = 0 To phone.Length - 1
            If InStr(sValidString, phone.Substring(iCtr, 1)) > 0 Then
                result = result & phone.Substring(iCtr, 1)
            End If
        Next

        If result = Nothing Then
            result = ""
        End If
        FilterPhone = result
    End Function
 
End Class
